package io

import (
	"io/ioutil"
	"log"
	"os"
	"fmt"
)

func ReadAll(pngName string) []byte  {
	data, err := ioutil.ReadFile(pngName);
	if nil != err {
		log.Printf("读取文件%s失败，错误原因：%v \n", pngName, err);
		return nil;
	}
	return data;
}

func ReadAllFile(pngName string) string{
	var data string;
	file, error := os.Open(pngName);
	if nil != error{
		log.Printf("打开文件%s失败,错误原因：%v \n", pngName, error)
	}
	defer file.Close();
	for{
		block := make([]byte, 1024);
		length, error := file.Read(block);
		if nil != error && "EOF" != error.Error(){
			log.Printf("读取文件%s错误， 错误原因: %v \n", pngName, error);
			return data;
		}
		if length <= 0 {
			fmt.Printf("文件%s读取完成 \n", pngName);
			break;
		}
		data = data + string(block);
	}
	return data;
}

func WriteFile(pngName string, datas []byte){
	ioutil.WriteFile(pngName, datas, 1);
}
